package com.googlecode.restitory.gae;

import static org.junit.Assert.assertEquals;

import java.net.URL;

import com.googlecode.mycontainer.commons.io.IOUtil;
import com.googlecode.restitory.gae.http.HttpClientRequestService;
import com.googlecode.restitory.gae.http.Request;
import com.googlecode.restitory.gae.http.Response;
import com.googlecode.restitory.gae.http.Type;

public class AbstractWebTestCase extends AbstractTestCase {

	@Override
	public void setUp() throws Exception {
		helper = new GAETestHelper();
		helper.prepareLocalServiceTestHelper();
		helper.bootMycontainer();

		service = new HttpClientRequestService("http://localhost:8380");
	}

	@Override
	public void tearDown() {
		if (helper != null) {
			helper.shutdownMycontainer();
		}
	}

	public void putResource(String resource, String target) {
		URL url = getClass().getClassLoader().getResource(resource);
		char[] content = IOUtil.readChars(url);
		Response response = service.execute(new Request(Type.PUT, target).setContentType("application/json; charset=utf-8")
				.setContent(content));
		assertEquals(200, response.getCode());
	}

}
